package servlet;

import dao.AddressDao;
import dao.CartDao;
import dao.GoodsDao;
import entity.Address;
import entity.Cart;
import entity.Goods;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

@WebServlet("/selectAddress")
public class SelectAddressServlet extends HttpServlet {
	
	@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        doGet(request, response);
    }
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {

		System.out.println("-----------selectAddress------------");
		User user = (User) request.getSession().getAttribute("user");

		AddressDao dao = new AddressDao();
		List<Address> list = dao.selectMyAddress(user.getUserId());
		if(list == null) {
			response.sendRedirect("error.jsp");
			return;
		}else {
			request.getSession().setAttribute("myAddresses", list);
			response.sendRedirect("frontend/address.jsp");
		}

	}


}
